package com.example.dao.impl;

import com.example.Pojo.Book;
import com.example.Pojo.Operation;
import com.example.Pojo.Price;
import com.example.dao.OperationDao;

import java.util.List;

public class OperationDaoImpl extends BaseDao implements OperationDao {
    @Override
    public List<Operation> findAllOperations() {
        String sql = "select * from operation";
        return queryForList(Operation.class,sql);
    }

    @Override
    public int saveBookProject(Book book) {
        String sql = "insert into bookpro(username,telephone,booktime,project)values(?,?,?,?)";
        return update(sql,book.getUsername(),book.getTelephone(),book.getBooktime(),book.getProject());
    }

    @Override
    public Price getPrice() {
        String sql = "select * from price";
        return queryForOne(Price.class,sql);
    }

    @Override
    public int deleteBook(String telephone) {
        String sql = "delete from bookpro where telephone=?";
        return update(sql,telephone);
    }

    @Override
    public Integer countOperation() {
        String sql = "select count(*) from operation";
        Number count = (Number) queryCounts(sql);
        return count.intValue();
    }

    @Override
    public int deleteOne() {
        String sql = "delete from operation where 1 order by time limit 1";
        return update(sql);
    }
}
